package io.demo.qsprotobuf;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;
import org.springframework.web.reactive.function.client.WebClient;

import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;

@Slf4j
public class QsProtobufIT {

    @Test
    public void test() {
        WebClient webClient = WebClient.create("http://localhost:8080");
        Mono<Course> course = webClient.get()
            .uri("courses/{id}", 1)
            .retrieve()
            .bodyToMono(Course.class);
        course.subscribe(this::assertCourse);

        Mono<Void> all = Mono.when(course);
        all.block();
    }

    private void assertCourse(Course course) {
        log.info("{}: {}", Course.class, course);
        assertThat(course).isNotNull();
        assertThat(course.getCourseName()).isEqualTo("REST with Spring");
        assertThat(course.getStudentCount()).isEqualTo(3);
    }
}